class Solution2 {
    public int singleNumber(int[] nums) {
        int ret = 0;
        for (int i = 0; i < 32; i++) {
            int x = 0;
            for (int j = 0; j < nums.length; j++) {
                if (((nums[j] >> i) & 1) == 1) {
                    x++;
                }
            }
            x %= 3;
            ret |= x << i;
        }
        return ret;
    }
}